home *** CD-ROM | disk | FTP | other *** search
/ MacFormat 1995 August / macformat-027.iso / mac / Portables / Newton / Dev / newt-25 folder / applic2.nwt < prev    next >
Encoding:
Text File  |  1995-01-22  |  5.4 KB  |  218 lines  |  [TEXT/R*ch]

  1. Notes
  2. {labels: 'NIL, viewFont: 10241} // nil=Unfiled, or specify a folder, e.g., 'Business.  remove viewFont for current Styles default
  3. //ERASE! in order to erase existing entries in this folder first
  4.  
  5. applic2.nwt -- Slurpee format
  6. 1/1/95
  7. Copyright 1994, 1995 S. Weyer.  All Rights Reserved Worldwide.
  8. To be distributed only with Newt 2.5 package
  9.  
  10. expanded MyApp example using more prototypes
  11. see applic0.nwt for simpler example
  12.  
  13. see applic3.nwt for same version as applic2.nwt but using
  14. earlier, more direct :addApp, :addStep syntax
  15. ----------
  16. MyApp2
  17. //:doObj('buildCO,'MyApp2)
  18. //:doObj('add,'MyApp2)
  19. //:doObj('remove,'MyApp2)
  20. {_proto: 'protoApp,
  21. title: "Hello World -- on Steroids",
  22. }
  23. ----------
  24. MyApp2.myNumberInputLineProto
  25. {_proto: 'protoInputLine,
  26. text: "enter a number",
  27. value: 0,
  28. viewFlags: 10753, //vVisible + vClickable + vGesturesAllowed + vNumbersAllowed
  29. viewChangedScript: func(slot,view)
  30.     if slot='text
  31.     then begin
  32.         value := StringToNumber(text);
  33.         if not value then value := 0;
  34.         if aTotal exists then aTotal:update();
  35.         end,
  36. viewSetupFormScript: func()
  37.     begin
  38.     self.text := clone(text);
  39.     self.value := 0;
  40.     inherited:?viewSetupFormScript();
  41.     end,
  42. }
  43. ----------
  44. MyApp2+float
  45. {_proto: 'protoFloatNGo,
  46. viewBounds: RelBounds(20,50,150,90),
  47. }
  48. ----------
  49. MyApp2.float+aboutText
  50. {viewclass: 'clParagraphView,
  51. text: "This wonderful application from the \"kitchen sink school of user interface design\" created by "&
  52.     userConfiguration.name&      // the developer's name
  53.     ", with the help of Newt, the lizard wizard",
  54. viewFlags: 3, //vReadOnly+vVisible,
  55. viewBounds: RelBounds(5,5,140,80), // relative to aFloat
  56. }
  57. ----------
  58. MyApp2+button
  59. {_proto: 'protoTextButton,
  60. text: "About",
  61. viewBounds: RelBounds(20,30,40,16),
  62. buttonClickScript: func()
  63.     if float exists
  64.     then float:open()
  65.     else PlaySound(@102), // ROM_funbeep
  66. }
  67. ----------
  68. MyApp2+num1
  69. {_proto: 'myNumberInputLineProto, // use user prototype defined in app
  70. text: "first number", // needs to be set so protos don't share text string
  71. viewBounds: RelBounds(130,20,100,20),
  72. }
  73. ----------
  74. MyApp2+num2
  75. {_proto: 'myNumberInputLineProto,
  76. text: "second number",
  77. viewBounds: RelBounds(130,45,100,20),
  78. }
  79. ----------
  80. MyApp2+aTotal
  81. {_proto: 'protoStaticText,
  82. text: "Total",
  83. vars: ['num1, 'num2,], // same names as two fields
  84. viewBounds: RelBounds(130,80,100,16),
  85. update: func()
  86.     begin
  87.     local tot := 0, field;
  88.     foreach field in vars // add up num1.value+num2.value etc.
  89.     do tot := tot + GetVariable(self,field).value;
  90.     if round exists and round.viewValue
  91.     then tot := RIntToL(tot);
  92.     SetValue(self,'text,NumberStr(tot));
  93.     end,
  94. }
  95. ----------
  96. MyApp2+round
  97. {_proto: 'protoRCheckbox, // checkbox on right & text on left
  98. text: "Round?",
  99. indent: 40,
  100. viewBounds: RelBounds(10,78,50,16), 
  101. valueChanged: func() aTotal:update(),
  102. }
  103. ----------
  104. MyApp2+aTextval
  105. {_proto: 'protoStaticText,
  106. text: "xxx",
  107. viewBounds: RelBounds(150,240,100,16),
  108. }
  109. ----------
  110. MyApp2+labelLine
  111. {_proto: 'protoLabelInputLine,
  112. viewBounds: RelBounds(10,110,200,20),
  113. label: "a label",
  114. textSetup: func() clone("some string"), // initial value
  115. labelCommands: ["A", "B", "C"],  // optional
  116. textChanged: func()
  117.     SetValue(aTextval,'text,entryLine.text),
  118. }
  119. ----------
  120. MyApp2+picker
  121. {_proto: 'protoLabelPicker,
  122. text: "picker",
  123. viewBounds: RelBounds(10,140,100,16), 
  124. labelCommands: ["one", "two", "three",],
  125. labelActionScript: func(cmd)
  126.     SetValue(aTextval,'text,labelCommands[cmd]),
  127. }
  128. ----------
  129. MyApp2+slider
  130. {_proto: 'protoSlider,
  131. viewBounds: RelBounds(10,160,100,12),
  132. minValue: 1,
  133. maxValue: 3,
  134. viewSetupFormScript: func()
  135.     viewValue := (maxValue+minValue)/2,
  136. changedSlider: func()
  137.     SetValue(aTextval,'text,NumberStr(viewValue)),
  138. }
  139. ----------
  140. MyApp2+radiobuttons
  141. {_proto: 'protoRadioCluster,
  142. viewBounds: RelBounds(150,190,100,50),
  143. clusterChanged: func()
  144.     SetValue(aTextval,'text,NumberStr(clusterValue)),
  145. }
  146. ----------
  147. MyApp2.radiobuttons+ten
  148. {_proto: 'protoRadioButton,
  149. text: "diez",
  150. buttonValue: 10,
  151. viewBounds: RelBounds(0,0,60,15), // relative to radiobuttons
  152. }
  153. ----------
  154. MyApp2.radiobuttons+twenty
  155. {_proto: 'protoRadioButton,
  156. text: "veinte",
  157. buttonValue: 20,
  158. viewBounds: RelBounds(0,15,60,15),
  159. }
  160. ----------
  161. MyApp2.radiobuttons+thirty
  162. {_proto: 'protoRadioButton,
  163. text: "treinta",
  164. buttonValue: 30,
  165. viewBounds: RelBounds(0,30,60,15),
  166. }
  167. ----------
  168. MyApp2+textlist
  169. {_proto: 'protoTextlist,
  170. viewBounds: Relbounds(150,140,60,40),
  171. viewSetupFormScript: func()
  172.     begin 
  173.     self.listItems := ["larry","moe","curly"];
  174.     //viewLines := length(listItems);
  175.     :setupList() ;
  176.     inherited:?viewSetupFormScript();
  177.     end,
  178. viewLines: 3,
  179. buttonClickScript: func(i)
  180.     SetValue(aTextval,'text,listitems[i]),
  181. }
  182. ----------
  183. MyApp2+expando
  184. {_proto: 'protoExpandoShell,
  185. viewBounds: RelBounds(10,185,120,70),
  186. numLines: 2,
  187. viewFormat: 337, // vfFillWhite+vfFrameBlack+vfPen=1
  188. editHeight: 46, // height of expanded field
  189. editWidth: 80,
  190. indent: 50, // left edge of value
  191. myExpandoProto:
  192.     {_proto: 'protoTextExpando,
  193.     label: "a label",
  194.     path: 'var,
  195.     },
  196. viewSetupFormScript: func()
  197.     begin local i, symslot;
  198.     self.target := self;
  199.     self.lines:=array(numLines,nil);
  200.     for i:=1 to numLines
  201.     do begin
  202.         symslot := intern("var"&i);
  203.         lines[i-1]:=
  204.             {_proto: myExpandoProto, // not quoted since evaluated at setup time
  205.             label: "Field "&i,
  206.             path: symslot,  // e.g., 'var1
  207.             };
  208.         SetValue(self,symslot,clone(""));
  209.         end;
  210.     inherited:viewSetupFormScript();
  211.     end,
  212. FlushEdits: func() nil, //inherited:?FlushEdits(), // no method to inherit?
  213. CloseEdit: func(view) // expanded field just closed
  214.     SetValue(aTextval,'text, target.(view.path)),
  215. }
  216. ----------
  217. BYE!
  218.